// pages/jilu/jilu.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    record:[],
    openid:'',
    lostmanName:'',
  },
  /**
   * 获取需要搜索的老人名字
   */
  lostmanName_put:function(e){
    this.setData({
      lostmanName:e.detail.value
    });
    console.log("搜索内容输入：",this.data.lostmanName);
    this.search();
  },
  /**
   * 访问接口
   */
  search:function(){
    wx.request({
      url: 'https://www.lanotherl.com/family/getReportRecords',
      data:{
        openid:this.data.openid,
        lostmanName:this.data.lostmanName
      },
      success:res=>{
        console.log("访问接口成功，返回的数据为：",res.data.data.records)
        this.setData({
          record:res.data.data.records
        })
      },
      fail:err=>{
        console.log("数据请求错误",err)
      }
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    wx.cloud.callFunction({
      name: 'getOpenid',
      complete: res => {
        console.log('云函数获取到的openid: ', res.result.openId)
        var openid = res.result.openId;
        that.setData({
          openid: openid
        })
        this.search();
      }
    })
  },

})